/**
 * Created by Jay on 2016/6/7.
 */
function  user_management(){
    $("body").off();//先解绑 好恐怖QAQ 被吊起来打了QAQ。不用怕 超人来了！！韩寒会画画
    var data_id;//保存id、、
    var this_data,meth,data_ty,add_data,first_data;
    $("body").on("click",".rep_search_lab",function(){
        if($(".rep_search_real_user").val()!=""||$("#select_d_user").val()!=2){
             this_data="memberController/searchMember";
             meth="post";
             add_data={condition:$(".rep_search_real_user").val(),sex:$("#select_d_user").val()};
             data_ty={pageSize:10,pageNo:1};
             first_data={pageSize:10,pageNo:1,nickName:$(".rep_search_real_user").val(),number:$("#input_num_munber").val(),sex:$("#select_d_user").val()}
        }else{
             this_data="memberController/getAllMember";
             meth="get";
             data_ty={pageSize:10,pageNo:1};
            first_data={pageSize:10,pageNo:1}
        }
          $.ajax({
              url:this_data,
              method:meth,
              data:first_data
          })
          .done(function(data){
              sessionStorage.setItem("this_page_click_num","1");
              set_seqsum(
                  {
                      pageNo:data.result.pageNo,
                      pageSize:data.result.pageSize
                  }
              );
              create_page({
                  url:this_data,
                  method:meth,
                  data:data,
                  temp:"userManagementTbody",
                  contain:"#ColumnTableData_user_m",
                  prePageSize:data.result.pageSize,
                  prepageNo:data.result.pageNo,
                  add_data:add_data
              })//生成分页
              two_ccc(data);
          })
    })

    mccmsa.ajax({
        url:"memberController/getAllMember",
        method:"get",
        data:{pageSize:10,pageNo:sessionStorage.getItem("this_page_click_num")},
        success:function(data){
            console.log(data);
            var prepageSize=data.result.pageSize;
            //console.log(data);
            //sessionStorage.setItem("this_page_click_num",1);//初始化为1；
            //sessionStorage.setItem("create_num",1);//初始化为1
            set_seqsum(
                {
                pageNo:data.result.pageNo,
                pageSize:data.result.pageSize
                 }
             );
            create_page({
                url:"memberController/getAllMember",
                method:"get",
                data:data,
                temp:"userManagementTbody",
                contain:"#ColumnTableData_user_m",
                prePageSize:data.result.pageSize,
                prepageNo:data.result.pageNo
            })//生成分页
            two_ccc(data);
        }
    })

    function two_ccc(data){
        mccmsa.getHtmlFromLocalTemplate({   //将数据打包到模版丢进容器 都打成包了QAQ 是人不是。。
            templateId: "userManagementTbody",
            container: $("#ColumnTableData_user_m"),
            data:data,
            callback: function(){
                $("body").on("click",".jingyan",function(){
                    var this_id=$(this).attr("data-id");
                    mccmsa.ajax({
                        url: "memberController/banOrClBan?"+"userId="+this_id,
                        method: "GET",
                        success: function (data) {
                            if(data.status=="200"){
                                mccmsa.hashChange();
                            }
                            //console.log(data);
                        },error:function(data){
                        }
                    })
                })//禁言
                $("body").on("click",".pingjia",function(){
                    var pj_id=$(this).attr("data-id");
                    mccmsa.goTo("user_comment","user_management_jh",{pj_id:pj_id});
                });//goto用户评论页面
                $("body").on("click",".this_click",function(){
                    var this_id=$(this).attr("data-id");
                    mccmsa.goTo("user_management_detail_jh","user_management_jh",{id:this_id});
                })//详情页
                $("body").on("click",".feng",function(e){
                    e.preventDefault();
                    e.stopPropagation();
                    var this_id = $(this).attr("data-id");
                    var feng_status=$(this).attr("data-status");
                    if(feng_status==1){
                        feng_status=0;
                    }
                    else if(feng_status==0){
                        feng_status=1;
                    }//取反
                    mccmsa.ajax({
                        url: "memberController/updateStatus?userId="+this_id+"&status="+feng_status,
                        method: "get",
                        success:function(data){
                            mccmsa.hashChange();//刷新页面
                        }
                    })
                    return false;
                })//封号或解封操作

                $("body").on("click",".jhh",function(){
                    $("#mymodal").modal("show");
                })//配备解惑号
                $(".myModal").on("click",function(){
                    data_id=$(this).attr("data-id");
                    //console.log("old:"+data_id);
                })//保存用户id
                $(".jh_num_save").click(function(){
                    //console.log(data_id);
                    var jh_num=$("#jh_num").val();
                    var x=/^[0-9]{8}$/;//8位的数值
                    if(!x.test(jh_num)){
                        layer.alert("请输入8位数的数字");
                    }
                    mccmsa.ajax({
                        url: "memberController/updateNumber",
                        method: "POST",
                        data: {userId: data_id, number:jh_num},
                        success: function (data) {
                            if(data.status==200){
                                layer.open({
                                    content: '成功',
                                    yes: function(index, layero){
                                        //do something
                                        layer.close(index); //如果设定了yes回调，需进行手工关闭
                                        $('#mymodal').modal('hide');//并且关闭下面的弹出层、、不行。。我嚓
                                    }
                                });
                            }else{
                                layer.alert("解惑号已被使用");
                            }
                        }
                    })
                })//配备解惑号
            }
        });
    }
}